# -*- coding: utf-8 -*-
"""
:mod:`nubox.shim`
=================

(internal) Provides compability between Python 2.6+, Jython 2.5+ and (not yet) 
Python 3.1+.

"""
from __future__ import (division, with_statement, absolute_import, generators,
                         nested_scopes)
import sys, platform

# determine python version
PYTHON3, PYTHON2, PYTHON26, PYTHON25 = False, False, False, False
if sys.version_info >= (3, 0):
    PYTHON3 = True
    raise RuntimeError("Python 3.x is not supported")
elif sys.version_info >= (2, 6):
    PYTHON26 = True
    PYTHON2 = True
elif sys.version_info >= (2, 5):
    PYTHON25 = True
    PYTHON2 = True
else:
    raise RuntimeError("minimum Python version is 2.5")
# determine python implementation
JYTHON = platform.system() == "Java"

# provide types
if PYTHON26:
    unicode = unicode
    str = str
    basestring = (bytes, str)
    bytes = str
    int = int
    long = long
elif PYTHON25:
    unicode = unicode
    str = str
    basestring = (unicode, str)
    bytes = str
    int = int
    long = long
#elif PYTHON3:
#    unicode = str
#    basestring = (unicode, bytes)
#    str = bytes
#    bytes = bytes
#    int = int
#    long = int

# provide functions

if PYTHON26:
    from urllib import urlencode # @UnusedImport
    from urllib2 import urlopen  # @UnusedImport
    reduce = reduce
    xrange = xrange
    from itertools import izip # @UnusedImport
    from itertools import product # @UnusedImport
elif PYTHON25:
    from urllib import urlencode # @UnusedImport
    from urllib2 import urlopen  # @UnusedImport
    reduce = reduce
    xrange = xrange
    from itertools import izip # @UnusedImport
    def product(*args, **kwds):
        pools = map(tuple, args) * kwds.get('repeat', 1)
        result = [[]]
        for pool in pools:
            result = [x + [y] for x in result for y in pool]
        for prod in result:
            yield tuple(prod)
#elif PYTHON3:
#    from urllib.parse import urlencode #@UnresolvedImport @UnusedImport
#    from urllib.request import urlopen # @UnresolvedImport @UnusedImport
#    from functools import reduce # @UnusedImport
#    xrange = range
#    izip = zip  # @UnusedVariable
#    from itertools import product  # @UnusedImport

del sys, platform
